package com.kly.order.db.dao.impl;

import com.alibaba.fastjson.JSONObject;
import com.fqgj.common.api.Page;
import com.fqgj.common.base.AbstractBaseMapper;
import com.google.common.collect.Maps;
import com.kly.order.db.dao.UserVasPurchasesDao;
import com.kly.order.db.entity.UserVasPurchasesEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * User: 11437
 * Date: 2023-06-01
 * Time: 09:27:21.736
 */
@Slf4j
@Repository
public class UserVasPurchasesDaoImpl extends AbstractBaseMapper<UserVasPurchasesEntity> implements UserVasPurchasesDao {
    @Override
    public List<UserVasPurchasesEntity> selectByUserCode(Map<String, Object> params) {
        return this.getSqlSession().selectList(this.getStatement("selectByUserCode"), params);
    }

    @Override
    public List<UserVasPurchasesEntity> queryBenefits(Page page) {
        final HashMap<String, Object> params = Maps.newHashMap();
        params.put("offset", page.getStartIndex());
        params.put("limit", page.getEndIndex());
        log.info("queryBenefits, page:{}", JSONObject.toJSONString(page));
        return this.getSqlSession().selectList(this.getStatement("queryBenefits"), params);
    }

    @Override
    public int queryBenefitsTotal() {
        return this.getSqlSession().selectOne(this.getStatement("queryBenefitsTotal"));
    }

    @Override
    public List<UserVasPurchasesEntity> queryBenefitsByUserCode(String userCode) {
        return this.getSqlSession().selectList(this.getStatement("queryBenefitsByUserCode"), userCode);
    }

    @Override
    public int updateUsageCount(int usageCount, String userCode, int benefitCode) {
        final HashMap<String, Object> params = Maps.newHashMap();
        params.put("usageCount", usageCount);
        params.put("userCode", userCode);
        params.put("benefitCode", benefitCode);
        return this.getSqlSession().update(this.getStatement("updateUsageCount"), params);
    }

    @Override
    public int updateAllUserBenefits() {
        return this.getSqlSession().update(this.getStatement("updateAllUserBenefits"));
    }
    @Override
    public int updateFlashChatAndWlmBenefits() {
        return this.getSqlSession().update(this.getStatement("updateFlashChatAndWlmBenefits"));
    }
}